package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags="分类·修改接口·")
public class CategoryController {


    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增分类")
    public Result add(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增分类：{}", categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();
    }

    /**
     * 分类分页查询
     * @param
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> page(@RequestBody CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("分页查询：{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /*/**
     * @description: TODO
          删除分类
     * @return
            * @author: liuqing
            * @date: 2025/7/30 16:11
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("删除分类")
    public Result delete(@PathVariable Long id) {
        log.info("删除分类：{}", id);
        categoryService.delete(id);
        return Result.success();
    }

    /**
     * @description: TODO
         根据id查询信息
     * @return
            * @author: liuqing
            * @date: 2025/7/30 16:11
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id查询信息")
    public Result<Category> getById(@PathVariable Long id){
        log.info("根据id查询信息：{}", id);
        Category category = categoryService.getById(id);
        return Result.success(category);
    }

    /**
     * @description: TODO
         修改分类
     * @return
            * @author: liuqing
            * @date: 2025/7/30 16:11
     */
    @PostMapping("/update")
    @ApiOperation("修改分类")
    public Result update(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改分类：{}", categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }

    /**
     * @description: TODO
       启用、禁用分类
     * @return
            * @author: liuqing
            * @date: 2025/7/30 16:11
     */
    @GetMapping("/startOrStop/{status}/{id}")
    @ApiOperation("启用、禁用分类")
    public Result startOrStop(@PathVariable Integer status, @PathVariable Long id) {
        log.info("启用、禁用分类：{}", id);
        categoryService.startOrStop(status, id);
        return Result.success();
    }

    @GetMapping("list")
    @ApiOperation("根据类型查询分类")
    public Result<List<Category>> list(Integer type){
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }

}
